/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ie.tcd.cs.railtickets.commons.util;

import java.text.ParseException;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;

/**
 *
 * @Created on 28-Apr-2009, 09:22:37
 * @author Wenbo Sun
 */
public class DateUtil {

    public static Date createDate(String src, String format) throws ParseException {
        Date dest = null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dest = sdf.parse(src);
        return dest;
    }

    public static Calendar createCalendar(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;

    }

    public static Date mergeDateTime(Date date, Date time) {
        date.setHours(time.getHours());
        date.setMinutes(time.getMinutes());
        date.setSeconds(time.getSeconds());
        return date;
    }

    public static Date DatePlusHours(Date date, double hours) {
        Double h = new Double(hours * 3600);
        date.setSeconds(date.getSeconds() + h.intValue());
        return date;
    }

    public static String DateToString(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}
